package com.salesys.tony.service;

import java.util.ArrayList;
import java.util.List;
import com.salesys.gr.dao.ConverDao;
import com.salesys.gr.dao.RecordDao;
import com.salesys.gr.util.TimeHelper;
import com.salesys.tony.domain.Record;

public class RecordService {
	public int addMarkRecord(int userId, String markSource) {
		int affect = 0;
		String mark = null;
		String markPercent = new ConverDao().queryMarkPercentFromMarkSource(markSource);
		if (markPercent != null) {
			mark = ((int) (200 * Integer.parseInt(markPercent) * 0.01)) + "";
			do {
				affect = new RecordDao().addRecord(userId, mark, markSource, TimeHelper.getSystemTime());
			} while (affect != 1);
		}
		return affect;
	}

	public int addParentMarkRecord(int userId, String mark, String markSource) {
		int affect = 0;
		do {
			affect = new RecordDao().addRecord(userId, mark, markSource, TimeHelper.getSystemTime());
		} while (affect != 1);
		return affect;
	}

	public List<Record> queryMarkRecordFromUserid(String userId) {
		List<Record> recordList = new ArrayList<Record>();
		recordList = new RecordDao().queryMarkRecordFromUserid(userId);
		return recordList;
	}

	public String queryChildLevelFromMarkSource(String markSource) {
		String childLevel = null;
		String child[] = markSource.split("_");
		childLevel = child[1];
		return childLevel;
	}
}
